package org.evasoft.museum.cataloger.json.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.evasoft.museum.cataloger.dto.EntryDTO;
import org.evasoft.museum.cataloger.dto.RecordDTO;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("json-default")
@Namespace("/data/catalog")
public class RecordListAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3687051842844887384L;
	
	private List<RecordDTO> records;

	public List<RecordDTO> getRecords() {
		return records;
	}
	
	@Action(value="getRecordList", results= {
			@Result(name="success",type="json")
	})
	public String execute(){
		records = createRecords();
		return SUCCESS;		
	}
	
	public List<RecordDTO> createRecords(){
		List<RecordDTO> records = new ArrayList<RecordDTO>();
		for(long i=0;i<=10;i++){
			records.add(createRecord(i));
		}
		return records;
	}
	
	public RecordDTO createRecord(Long id){
		RecordDTO record= new RecordDTO();
		record.setId(id);
		record.setCatalog("Obras");
		record.setEntries(createEntries());
		return record;
	}
	
	public List<EntryDTO> createEntries(){
		List<EntryDTO> entries = new ArrayList<EntryDTO>();
		EntryDTO entry = new EntryDTO("nombre","Nombre de la ora");
		EntryDTO entry1 = new EntryDTO("titulo","Titulo de la obra");
		EntryDTO entry2 = new EntryDTO("dimensiones","Dimensiones de la obra");
		EntryDTO entry3 = new EntryDTO("cronologia","Cronologiade laobra");
		EntryDTO entry4 = new EntryDTO("fechaCreacion","Fecha de creación de la obra");
		
		entries.add(entry);
		entries.add(entry1);
		entries.add(entry2);
		entries.add(entry3);
		entries.add(entry4);
		return entries;
	}


	
	

}
